package com.yuanxiao.common.api.base;

import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yuanxiao.common.api.constant.UsedType;
import com.yuanxiao.common.api.entity.dto.UserMemberDTO;
import com.yuanxiao.common.api.service.FeignBaseService;
import com.yuanxiao.common.core.result.R;
import com.yuanxiao.common.web.util.JwtUtils;


/**
 * Manager Controller 公共组件
 */
public abstract class MemberBaseController {
    protected Logger logger = LoggerFactory.getLogger (getClass ());

//    protected UserMemberDTO getUser() {
//        UserMemberDTO user = new UserMemberDTO();
//        user.setId(1603374159499362304L);
//        user.setSuperiorId(0L);
//        user.setSuperior("上级领导");
//        user.setDeptId(0L);
//        user.setDeptIds(",0,");
//        user.setCreateTime(new Date());
//        user.setEditorId(0L);
//        user.setEditor("root");
//        user.setRealName("admin");
//        user.setIdNo("530302198602250698");
//        user.setIdImg("");
//        user.setIsFacialRecognitionVerify("N");
//        user.setDetectInfo("");
//        user.setMobilePhone("15287471004");
//        user.setWechatOpenId("oBrnf5GmvFd8BDy7TbetXlbUcXEU");
//        user.setWechatNick("admin");
//        user.setWechatAvatarUrl("");
//        user.setWechatUnionId("xxxxxxxx");
//        user.setIntegral(99);
//        user.setIntegral(500);
//        return user;
//    }

    protected UserMemberDTO getUser() {
        return JSONUtil.toBean (JwtUtils.getUserInfoJSON (), UserMemberDTO.class);
    }

    protected boolean judgeDataAuthorityAboutDeptIdArgs(Long memberId) {
        return memberId.longValue() == getUser().getId().longValue();
    }

    /**
     * 远程校验
     * @param serverCode 服务代号
     * @param bizCode
     * @return
     */
    protected R judgeArgsByFeign(FeignBaseService feignBaseService, UsedType usedType, String serverCode, String bizCode, Object bodyArgs, Object pathArgs) {
       return feignBaseService.feignCall(serverCode, usedType, bizCode, bodyArgs, pathArgs);
    }

}
